package main

import (
	"fmt"
	"runtime"
	"sync"
)

func printChars(prefix string, wg *sync.WaitGroup) {
	defer wg.Done() // 通过信号量通知执行结束
	for i := 'a'; i <= 'z'; i++ {
		fmt.Printf("%s:%c\n", prefix, i)
		// 让出CPU
		// time.Sleep(time.Microsecond * 1)
		runtime.Gosched()
	}
}

func main() {
	// 定义信号量
	var wg = new(sync.WaitGroup)
	n := 10
	// wg := &sync.WaitGroup{}

	// 创建例程
	wg.Add(n)
	for i := 0; i < n; i++ {
		go printChars(fmt.Sprintf("printChars%02d", i), wg)
	}
	wg.Wait() // 等待所有例程结束

}
